<template>
  <div v-if="!pageLoading">
    <div class="searchBox">
      <el-form :inline="true">
        <el-form-item label="键名：">
          <el-input v-model="controlData.model.propKey" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="键值：">
          <el-input v-model="controlData.model.value" placeholder="请输入内容"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="addProps">保存</el-button>
        </el-form-item>
      </el-form>
    </div>

    <qm-table
      ref="qmTable"
      :data="query"
      :showToolbar="false"
      keyProp="propId"
      :showView="false"
      :showEdit="false"
      :showCheckbox="false"
    >
      <qm-table-column field="propKey">键名</qm-table-column>
      <qm-table-column field="value">键值</qm-table-column>
    </qm-table>

    <el-alert title="内置键名说明：" :closable="false" type="success">
      <b>processUrl：</b> 自定义该环节的工作流事项处理类（继承工作流基类的Controller）;
      <br />
      <b>viewUrl：</b> 自定义该环节的视图，如果后台处理都一样，仅仅是前端页面不一样，可采用这种方式;
      <br />
      <b>autoSend：</b> 标识该环节在超过设定时间后自动发送。配置格式：2w(在2个工作后发送)、3n(在3个自然日后发送)、2w|toDeptManager(在2个工作日后按指定迁移[分支id]发送)
      ，也可不指定迁移，让系统自动计算，但涉及变量需要将表单数据传入，就需要配置 serviceClass，例如：2w,com.qm.boot.web.workflow.service.impl.DemoLeaveApplyServiceImpl ;
      <br />
    </el-alert>
  </div>
</template>

<script>
import Controller from "@/libs/framework/controller";
import request from "@/utils/request";
export default class Instance extends Controller {
  onBeforeInit() {
    this.urls = {
      model: "/workflow/actExtTaskProp/getListModel",
      query: "/workflow/actExtTaskProp/query",
      delete: "/workflow/actExtTaskProp/delete",
    };
  }

  showLoading() {
    return false;
  }

  onBeforeQuery(type, conditions, params) {
    if (type === "list") {
      params.query["definitionId"] = this.vm.definitionId;
      params.query["taskName"] = this.vm.taskName;
    }
  }

  onAfterQuery(type, isSuccess, result) {
    if (type === "form") {
      result.controlData.model.definitionId = this.vm.definitionId;
      result.controlData.model.taskName = this.vm.taskName;
    }
    return result;
  }

  mixin() {
    return {
      name: "act-ext-task-prop",
      props: {
        definitionId: String,
        taskName: String,
      },
      data() {
        return {
          controlData: {
            model: {},
          },
        };
      },
      methods: {
        addProps() {
          let model = this.controlData.model;
          if (!model.propKey) {
            this.notifyError("请输入键名");
            return;
          }

          let args = "?pageAction=create";
          if (model.propId) {
            args = "?pageAction=edit&propId=" + model.propId;
          }
          request({
            url: `/workflow/actExtTaskProp/save${args}`,
            method: "post",
            data: { model: model },
          }).then((r) => {
            if (r && r.success) {
              this.notifySuccess("保存成功");
              this.controlData.model.propKey = "";
              this.controlData.model.value = "";
              this.controlData.model.propId = "";
              this.searchQuery();
            } else {
              this.notifyError(r.message || "添加失败");
            }
          });
        },
      },
    };
  }
}
</script>

<style scoped lang="scss">
</style>
